package com.yanqu.road.server.manger.rank;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.config.beauty.BeautyInfo;
import com.yanqu.road.entity.config.patrons.PatronsInfo;
import com.yanqu.road.entity.config.skin.SkinInfo;
import com.yanqu.road.entity.config.vehicle.VehicleInfo;
import com.yanqu.road.entity.curio.config.CurioItemInfo;
import com.yanqu.road.entity.curio.enums.eCurioConditionType;
import com.yanqu.road.entity.decoration.MammonEffectResult;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserHistoryAttribute;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.player.UserPowerChild;
import com.yanqu.road.entity.rank.RankWorshipResult;
import com.yanqu.road.entity.rank.UnionRank;
import com.yanqu.road.entity.rank.UserRank;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionServerGroup;
import com.yanqu.road.logic.bussiness.player.UserActivityBussiness;
import com.yanqu.road.logic.bussiness.player.UserBussiness;
import com.yanqu.road.logic.bussiness.union.UnionBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.logic.helper.UnionHelper;
import com.yanqu.road.logic.pb.RankPb;
import com.yanqu.road.logic.rank.RankListModel;
import com.yanqu.road.logic.rank.UnionRankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.curio.CurioModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.MammonModule;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.manger.ConfigMgr;
import com.yanqu.road.server.manger.CrossUnionServerGroupMgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.curio.CurioConfigMgr;
import com.yanqu.road.server.manger.activity.curio.CurioMgr;
import com.yanqu.road.server.manger.config.BeautyMgr;
import com.yanqu.road.server.manger.config.PatronsMgr;
import com.yanqu.road.server.manger.config.SkinMgr;
import com.yanqu.road.server.manger.config.VehicleMgr;
import com.yanqu.road.server.manger.cross.CrossDataMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RankMgr extends TempMgr {

    private static Logger logger = LogManager.getLogger(RankMgr.class.getName());

    private static Object locker = new Object();

    private static Map<Integer, Map<Integer, RankListModel>> rankListModelMap = new ConcurrentHashMap<>();

    private static UnionRankListModel unionRankListModel;

    private static Map<Integer, Map<Integer, RankListModel>> activityRankListModelMap = new ConcurrentHashMap<>();

    private static long uploadToUnionCorssTime;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    public boolean save() {
        synchronized (locker) {
            for (Map<Integer, RankListModel> m : rankListModelMap.values()) {
                for (RankListModel rankListModel : m.values()) {
                    if ((rankListModel.getBigRankType() == eBigRankType.Normal.getValue() && rankListModel.getRankType() < 1000) ||
                            rankListModel.getBigRankType() == eBigRankType.Skin.getValue() ||
                            rankListModel.getBigRankType() == eBigRankType.Vehicle.getValue() ||
                            rankListModel.getBigRankType() == eBigRankType.Patrons.getValue() ||
                            rankListModel.getBigRankType() == eBigRankType.Beauty.getValue() ||
                            rankListModel.getBigRankType() == eBigRankType.CurioItem.getValue()
                    ) {
                        rankListModel.saveNormalRankList();
                    }
                }

            }
        }
        return true;
    }

    @Override
    public boolean reloadData() {
        Map<Integer, Map<Integer, RankListModel>> modelMap = new ConcurrentHashMap<>();
        modelMap.put(eBigRankType.Normal.getValue(), new ConcurrentHashMap<>());
        modelMap.put(eBigRankType.Skin.getValue(), new ConcurrentHashMap<>());
        modelMap.put(eBigRankType.Vehicle.getValue(), new ConcurrentHashMap<>());
        modelMap.put(eBigRankType.Patrons.getValue(), new ConcurrentHashMap<>());
        modelMap.put(eBigRankType.Beauty.getValue(), new ConcurrentHashMap<>());
        modelMap.put(eBigRankType.CurioItem.getValue(), new ConcurrentHashMap<>());

        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.EarnSpeed.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.EarnSpeed.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.PatronsAbility.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.PatronsAbility.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.TradeWarScore.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.TradeWarScore.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.BeautyIntimacy.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.BeautyIntimacy.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.HuntScore.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.HuntScore.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.Banquet.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.Banquet.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.ChildSpeed.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.ChildSpeed.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.Charitable.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.Charitable.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.ClinicValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.ClinicValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.CreditValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.CreditValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.EmbroideryMeter.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.EmbroideryMeter.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.ManorProsperousValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.ManorProsperousValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.WineShopPopularityValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.WineShopPopularityValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.FishPondScore.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.FishPondScore.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.GrandChildEarnSpeed.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.GrandChildEarnSpeed.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.AssistantDressOnValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(),eRankType.AssistantDressOnValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.WingRoomComfortValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(),eRankType.WingRoomComfortValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.DrugStroeTongBiValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(),eRankType.DrugStroeTongBiValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.WineryAroma.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.WineryAroma.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.CricketScore.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.CricketScore.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.HistoryMaxAbility.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.HistoryMaxAbility.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.KowloonProsperousValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.KowloonProsperousValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.WingRoomWindWaterValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(),eRankType.WingRoomWindWaterValue.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.MusicRoomRank.getValue(), new RankListModel(eBigRankType.Normal.getValue(), eRankType.MusicRoomRank.getValue()));
        modelMap.get(eBigRankType.Normal.getValue()).put(eRankType.CurioScoreValue.getValue(), new RankListModel(eBigRankType.Normal.getValue(),eRankType.CurioScoreValue.getValue()));

        for (SkinInfo skinInfo : SkinMgr.getSkinInfoMap().values()) {
            modelMap.get(eBigRankType.Skin.getValue()).put(skinInfo.getSkinId(), new RankListModel(eBigRankType.Skin.getValue(), skinInfo.getSkinId()));
        }

        for (VehicleInfo vehicleInfo : VehicleMgr.getVehicleInfoMap().values()) {
            if (VehicleMgr.canJoinRank(vehicleInfo.getId())) {
                modelMap.get(eBigRankType.Vehicle.getValue()).put(vehicleInfo.getId(), new RankListModel(eBigRankType.Vehicle.getValue(), vehicleInfo.getId()));
            }
        }

        for (PatronsInfo patronsInfo : PatronsMgr.getPatronsInfoMap().values()) {
            modelMap.get(eBigRankType.Patrons.getValue()).put(patronsInfo.getId(), new RankListModel(eBigRankType.Patrons.getValue(), patronsInfo.getId()));
        }
        modelMap.get(eBigRankType.Patrons.getValue()).put(0, new RankListModel(eBigRankType.Patrons.getValue(), 0));

        modelMap.get(eBigRankType.Beauty.getValue()).put(eRankType.Beauty.getValue(), new RankListModel(eBigRankType.Beauty.getValue(), eRankType.Beauty.getValue()));
        for (BeautyInfo beautyInfo : BeautyMgr.getBeautyInfoMap().values()) {
            modelMap.get(eBigRankType.Beauty.getValue()).put(beautyInfo.getBeautyId(), new RankListModel(eBigRankType.Beauty.getValue(), beautyInfo.getBeautyId()));
        }

        modelMap.get(eBigRankType.CurioItem.getValue()).put(eRankType.Curio.getValue(), new RankListModel(eBigRankType.CurioItem.getValue(), eRankType.Curio.getValue()));
        for (CurioItemInfo itemInfo : CurioConfigMgr.getConfig().getItemInfoMap().values()) {
            modelMap.get(eBigRankType.CurioItem.getValue()).put(itemInfo.getId(), new RankListModel(eBigRankType.CurioItem.getValue(), itemInfo.getId()));
        }

        for (Map<Integer, RankListModel> m : modelMap.values()) {
            for (RankListModel model : m.values()) {
                model.setRankNum(GameConfig.RANK_DEFAULT_MAX_COUNT);
                model.initRankList();
            }
        }
        rankListModelMap = modelMap;

        //商会排行榜
        unionRankListModel = new UnionRankListModel();
        unionRankListModel.setRankNum(GameConfig.UNION_RANK_DEFAULT_MAX_COUNT);
        //unionRankListModel.setRankList(getUnionRankListFromDb(GameConfig.UNION_RANK_DEFAULT_MAX_COUNT));

        return true;
    }

    public void addListener() {
        ServerGroupMgr.addReloadListener(() -> {
            groupChangeNotify();
        });
    }

    public static void initUnionRankListModel(){
        List<CrossUnionInfo> list = CrossUnionMgr.getUnionListInServer(GameServer.getInstance().getServerId());
        unionRankListModel.setRankList(parseCrossUnionRankList(list));
    }

    /**
     * 分组榜单通知
     */
    public static void groupChangeNotify() {
        for (RankListModel model : rankListModelMap.get(eBigRankType.Skin.getValue()).values()) {
            for (UserRank userRank : new ArrayList<>(model.getRankList())) {
                CrossDataMgr.groupRankChange(userRank);
            }
        }
        for (RankListModel model : rankListModelMap.get(eBigRankType.Vehicle.getValue()).values()) {
            for (UserRank userRank : new ArrayList<>(model.getRankList())) {
                CrossDataMgr.groupRankChange(userRank);
            }
        }
        for (RankListModel model : rankListModelMap.get(eBigRankType.Patrons.getValue()).values()) {
            for (UserRank userRank : new ArrayList<>(model.getRankList())) {
                if (userRank.getType() == 0) {
                    CrossDataMgr.groupAllPatronsRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            }
        }
        for (RankListModel model : rankListModelMap.get(eBigRankType.Beauty.getValue()).values()) {
            for (UserRank userRank : new ArrayList<>(model.getRankList())) {
                if (userRank.getType() == eRankType.Beauty.getValue()) {
                    CrossDataMgr.groupAllBeautyRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            }
        }
        for (RankListModel model : rankListModelMap.get(eBigRankType.CurioItem.getValue()).values()) {
            for (UserRank userRank : new ArrayList<>(model.getRankList())) {
                if (userRank.getType() == eRankType.Curio.getValue()) {
                    CrossDataMgr.groupAllCurioRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            }
        }
    }

    public static boolean uploadRankData() {
        try {
            for (Map<Integer, RankListModel> modelMap : rankListModelMap.values()) {
                for (RankListModel rankListModel : modelMap.values()) {
                    if (rankListModel.getBigRankType() == eBigRankType.Patrons.getValue()) {
                        for (UserRank userRank : new ArrayList<>(rankListModel.getRankList())) {
                            if (userRank.getType() == 0) {
                                CrossDataMgr.groupAllPatronsRankChange(userRank);
                            } else {
                                CrossDataMgr.groupRankChange(userRank);
                            }
                        }
                    } else if(rankListModel.getBigRankType() == eBigRankType.Beauty.getValue()){
                        for (UserRank userRank : new ArrayList<>(rankListModel.getRankList())) {
                            if (userRank.getType() == eRankType.Beauty.getValue()) {
                                CrossDataMgr.groupAllBeautyRankChange(userRank);
                            } else {
                                CrossDataMgr.groupRankChange(userRank);
                            }
                        }
                    } else if(rankListModel.getBigRankType() == eBigRankType.CurioItem.getValue()){
                        for (UserRank userRank : new ArrayList<>(rankListModel.getRankList())) {
                            if (userRank.getType() == eRankType.Curio.getValue()) {
                                CrossDataMgr.groupAllCurioRankChange(userRank);
                            } else {
                                CrossDataMgr.groupRankChange(userRank);
                            }
                        }
                    } else {
                        if (rankListModel.getRankType() != eRankType.HistoryMaxAbility.getValue()) {
                            for (UserRank userRank : new ArrayList<>(rankListModel.getRankList())) {
                                CrossDataMgr.groupRankChange(userRank);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            logger.error("upload rank error", e);
            return false;
        }
        RankProto.CrossNotifyUploadRankDataRespMsg.Builder respMsg = RankProto.CrossNotifyUploadRankDataRespMsg.newBuilder();
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_CROSS_RANK_UPLOAD_OVER_SYNC, respMsg);
        GamePlayerMgr.sendPacket(0, message);
        return true;
    }

    public static boolean uploadRankDataToUnionCross() {
//        if (!CrossDataMgr.isNeedUploadGroupRankToUnionCrossEmpty(eBigRankType.Normal.getValue(), eRankType.CorssHistoryMaxAbility.getValue())) {
//            return false;
//        }

//        if (!CrossUnionMgr.isAllSync()){
//            return false;
//        }

        if (!CrossDataMgr.checkUploadToUnionCrossTime(eBigRankType.Normal.getValue(), eRankType.CorssHistoryMaxAbility.getValue())){
            return false;
        }

        CrossDataMgr.addUploadToUnionCrossTime(eBigRankType.Normal.getValue(), eRankType.CorssHistoryMaxAbility.getValue(), DateHelper.getCurrentTime());

        try {
            List<UserInfo> userInfos = new ArrayList<>();
            Map<Long, BigInteger> abilityMap = new ConcurrentHashMap<>();
            UserBussiness.getUserAbilityRank(GameConfig.MONTH_ABILITY_RANK_ACTIVITY_DAYS, GameConfig.UNION_PLAYER_MONTH_ABILITY_RANK_IDENTITY_LEVEL,
                    userInfos, abilityMap);
            if (userInfos.isEmpty()){
                CrossDataMgr.uploadGroupRankToUnionCross(new ArrayList<>(), true);
            }
            List<UserRank> userRankList = new ArrayList<>();
            int rank = 1;
            for (UserInfo userInfo : userInfos) {
                UserRank userRank = new UserRank();
                userRank.setUserId(userInfo.getUserId());
                userRank.setRank(rank++);
                userRank.setBigRankType(eBigRankType.Normal.getValue());
                userRank.setType(eRankType.CorssHistoryMaxAbility.getValue());
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(userInfo.getUserId());
                if (null != player){
                    UserBaseInfo userBaseInfo = UserMgr.parseUserBaseInfo(player.getUserInfo(), GameServer.getInstance().getServerId());
                    userRank.setUserBaseInfo(userBaseInfo);
                    UserHistoryAttribute userHistoryAttribute = player.getModule(PlayerModule.class).getUserHistoryAttribute();
                    userRank.setValue(userHistoryAttribute.getAbility());
                    if (userRank.getValue().equals(BigInteger.ZERO)){
                        userRank.setValue(userBaseInfo.getTotalAbility());
                    }
                } else {
                    UserBaseInfo userBaseInfo = UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId());
                    userRank.setUserBaseInfo(userBaseInfo);
                    BigInteger value = abilityMap.getOrDefault(userInfo.getUserId(), BigInteger.ZERO);
                    userRank.setValue(value);
                    if (userRank.getValue().equals(BigInteger.ZERO)){
                        userRank.setValue(userBaseInfo.getTotalAbility());
                    }
                }

                userRankList.add(userRank);

            }
            CrossDataMgr.uploadGroupRankToUnionCross(userRankList, true);
        } catch (Exception e) {
            logger.error("upload rank error", e);
            return false;
        }
        return true;
    }


    public static UnionRankListModel getUnionRankList() {
        return unionRankListModel;
    }

    public static Map<Integer, RankListModel> getRankListModelMap(int bigRankType) {
        return rankListModelMap.get(bigRankType);
    }

    public static RankListModel getRankListModelByType(int bigRankType, Integer rankType) {
        return rankListModelMap.get(bigRankType).get(rankType);
    }

    /**
     * 藏品
     */
    public static void changeUserRank(int bigRankType, long userId, BigInteger value, Integer rankType, String param, long lastUpdateTime) {
        if (param == null) {
            param = "";
        }
        RankListModel rankListModel = getRankListModelByType(bigRankType, rankType);
        //藏品会屏蔽,启动时没有初始model
        if (rankListModel == null && bigRankType == eBigRankType.CurioItem.getValue()) {
            synchronized (locker) {
                if (getRankListModelByType(bigRankType, rankType) == null) {
                    Map<Integer, RankListModel> modelMap = rankListModelMap.get(bigRankType);
                    RankListModel model = new RankListModel(bigRankType, rankType);
                    model.setRankNum(GameConfig.RANK_DEFAULT_MAX_COUNT);
                    model.initRankList();
                    modelMap.put(rankType, model);
                }
            }

        }
        rankListModel = getRankListModelByType(bigRankType, rankType);
        if (null == rankListModel) {
            return;
        }

        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if(null == userInfo){
            return;
        }
        //管理员账号不参与排行
        if (userInfo.isAdmin() || userInfo.getBlackListEndTime() > System.currentTimeMillis()) {
            return;
        }
        //大于0的才参与排行榜
        boolean isNeedRank = false;
        boolean isDelete = false;
        if (value.compareTo(BigInteger.ZERO) > 0) {
            isNeedRank = true;
        }else {
            isDelete = rankListModel.removeUserRank(userId);
        }
        if(isNeedRank) {
            UserRank userRank;
            if (eBigRankType.CurioItem.getValue() == bigRankType) {
                if(rankType == eRankType.Curio.getValue()){
                    userRank = rankListModel.allRankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param, lastUpdateTime);
                }else {
                    userRank = rankListModel.rankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param, lastUpdateTime);
                }
                crossGroupRankChange(userRank);
            }
        } else if (isDelete) {
            UserRank deleteRank = rankListModel.initRank(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), BigInteger.valueOf(Long.MIN_VALUE), param);
            crossGroupRankChange(deleteRank);
        }
    }

    public static void changeUserRank(int bigRankType, long userId, BigInteger value, Integer rankType, String param) {
        if (param == null) {
            param = "";
        }
        RankListModel rankListModel = getRankListModelByType(bigRankType, rankType);
        if (rankListModel == null && bigRankType == eBigRankType.Skin.getValue()) {
            synchronized (locker) {
                if (getRankListModelByType(bigRankType, rankType) == null) {
                    // 先写死 只有皮肤才重新放进榜单
                    Map<Integer, RankListModel> modelMap = rankListModelMap.get(bigRankType);
                    SkinInfo skinInfo = SkinMgr.getSkinInfo(rankType);
                    if (skinInfo == null) {
                        return;
                    }
                    RankListModel model = new RankListModel(bigRankType, rankType);
                    model.setRankNum(GameConfig.RANK_DEFAULT_MAX_COUNT);
                    model.initRankList();
                    modelMap.put(rankType, model);
                }
            }
        }
        //藏品会屏蔽,启动时没有初始model
        if (rankListModel == null && bigRankType == eBigRankType.CurioItem.getValue()) {
            synchronized (locker) {
                if (getRankListModelByType(bigRankType, rankType) == null) {
                    Map<Integer, RankListModel> modelMap = rankListModelMap.get(bigRankType);
                    RankListModel model = new RankListModel(bigRankType, rankType);
                    model.setRankNum(GameConfig.RANK_DEFAULT_MAX_COUNT);
                    model.initRankList();
                    modelMap.put(rankType, model);
                }
            }

        }
        rankListModel = getRankListModelByType(bigRankType, rankType);
        if (null == rankListModel) {
            return;
        }
        
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if(null == userInfo){
            return;
        }
        //管理员账号不参与排行
        if (userInfo.isAdmin() || userInfo.getBlackListEndTime() > System.currentTimeMillis()) {
            return;
        }
        //大于0的才参与排行榜
        boolean isNeedRank = false;
        boolean isDelete = false;
        if (value.compareTo(BigInteger.ZERO) > 0) {
            isNeedRank = true;
        }else {
            if (eBigRankType.Normal.getValue() == bigRankType && rankType == eRankType.TradeWarScore.getValue()) {
                isNeedRank = true;
            } else if (bigRankType == eBigRankType.Vehicle.getValue() && value.compareTo(BigInteger.ZERO) >= 0) {
                isNeedRank = true;
            } else {
                isDelete = rankListModel.removeUserRank(userId);
            }
        }
        if(isNeedRank) {
            UserRank userRank;
            if (eBigRankType.Normal.getValue() == bigRankType && eRankType.EarnSpeed.getValue() == rankType) {
                UserRank oldFirst = rankListModel.getFirstRank();
                userRank = rankListModel.rankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
                UserRank newFirst = rankListModel.getFirstRank();
                long oldUserId = 0;
                long newUserId = 0;
                if (null != oldFirst) {
                    oldUserId = oldFirst.getUserId();
                }
                if (null != newFirst) {
                    newUserId = newFirst.getUserId();
                }
                if (oldUserId != newUserId && 0 != newUserId) {
                    UserInfo firstUserInfo = UserMgr.getUserInfo(newUserId);
                    WorldMessageMgr.worldNotify(eMessageType.EarnSpeedRankTopOne.getValue(), firstUserInfo.getCity(), firstUserInfo.getTitleId(),
                            firstUserInfo.getNickName());
                }
            } else if (eBigRankType.Patrons.getValue() == bigRankType && rankType == 0) {
                userRank = rankListModel.allPatronsRankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
            } else if (eBigRankType.Beauty.getValue() == bigRankType && rankType == eRankType.Beauty.getValue()) {
                userRank = rankListModel.allBeautyRankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
            } else if (eBigRankType.CurioItem.getValue() == bigRankType && rankType == eRankType.Curio.getValue()) {
                userRank = rankListModel.allBeautyRankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
            } else {
                userRank = rankListModel.rankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
            }
            crossGroupRankChange(userRank);
        } else if (isDelete && (bigRankType == eBigRankType.Vehicle.getValue() || bigRankType == eBigRankType.Beauty.getValue() || rankType == eRankType.WingRoomWindWaterValue.getValue())) {
            UserRank deleteRank = rankListModel.initRank(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), BigInteger.valueOf(Long.MIN_VALUE), param);
            crossGroupRankChange(deleteRank);
        }
    }

    public static void crossGroupRankChange(UserRank userRank) {
        if (userRank != null) {
            if (userRank.getBigRankType() == eBigRankType.Normal.getValue() &&
                    (userRank.getType() == eRankType.EarnSpeed.getValue() || userRank.getType() == eRankType.PatronsAbility.getValue()
                            || userRank.getType() == eRankType.BeautyIntimacy.getValue() || userRank.getType() == eRankType.EmbroideryMeter.getValue()
                            || userRank.getType() == eRankType.ManorProsperousValue.getValue() || userRank.getType() == eRankType.WineShopPopularityValue.getValue()
                            || userRank.getType() == eRankType.FishPondScore.getValue() || userRank.getType() == eRankType.GrandChildEarnSpeed.getValue()
                            || userRank.getType() == eRankType.AssistantDressOnValue.getValue() || userRank.getType() == eRankType.WingRoomComfortValue.getValue()
                            || userRank.getType() == eRankType.WingRoomWindWaterValue.getValue())
                    || userRank.getType() == eRankType.DrugStroeTongBiValue.getValue()
                    || userRank.getType() == eRankType.CurioScoreValue.getValue()
                    || userRank.getType() == eRankType.WineryAroma.getValue()
                    || userRank.getType() == eRankType.CricketScore.getValue()
                    || userRank.getType() == eRankType.HistoryMaxAbility.getValue()
                    || userRank.getType() == eRankType.KowloonProsperousValue.getValue()
                    || userRank.getType() == eRankType.MusicRoomRank.getValue()
            ) {
                CrossDataMgr.groupRankChange(userRank);
            } else if (userRank.getBigRankType() == eBigRankType.Skin.getValue()) {
                // 皮肤榜单上传
                CrossDataMgr.groupRankChange(userRank);
            } else if (userRank.getBigRankType() == eBigRankType.Vehicle.getValue()) {
                CrossDataMgr.groupRankChange(userRank);
            } else if (userRank.getBigRankType() == eBigRankType.Patrons.getValue()) {
                if (userRank.getType() == 0) {
                    CrossDataMgr.groupAllPatronsRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            } else if (userRank.getBigRankType() == eBigRankType.Beauty.getValue()){
                if (userRank.getType() == eRankType.Beauty.getValue()) {
                    CrossDataMgr.groupAllBeautyRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            } else if (userRank.getBigRankType() == eBigRankType.CurioItem.getValue()){
                if (userRank.getType() == eRankType.Curio.getValue()) {
                    CrossDataMgr.groupAllCurioRankChange(userRank);
                } else {
                    CrossDataMgr.groupRankChange(userRank);
                }
            }
        }
    }

    public static void changeActivityRank(int activityId, long userId, BigInteger value, String param) {
        RankListModel rankListModel = getRankListModelByType(eBigRankType.Normal.getValue(), activityId);
        if (null == rankListModel) {
            return;
        }
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if(null == userInfo){
            return;
        }
        // 管理员账号不参与排行
        if (userInfo.isAdmin() || userInfo.getBlackListEndTime() > System.currentTimeMillis()) {
            return;
        }

        UserRank userRank = rankListModel.rankChange(userId, UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()), value, param);
        if(NormalActivityMgr.isCrossActivity(activityId) && null != userRank){//跨服活动排行变更，排名前100名上榜
            CrossDataMgr.activityRankChange(activityId, userRank, true);
        } else {
            if(null == userRank){
                return;
            }
            ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
            if (activityInfo == null) {
                return;
            }
            if (activityInfo.getType() == eActivityType.CrossHuaShiGangActivity.getValue() ||
                    activityInfo.getType() == eActivityType.CrossDunHuangShiKuActivity.getValue()) {
                CrossDataMgr.activityRankChange(activityId, userRank, false);
            }
        }
    }

    public static void changeChildRank(long userId, UserPowerChild powerChild) {
        RankListModel rankListModel = getRankListModelByType(eBigRankType.Normal.getValue(), eRankType.ChildSpeed.getValue());
        if (null == rankListModel) {
            return;
        }
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if(null == userInfo){
            return;
        }
        // 管理员账号不参与排行
        if (userInfo.isAdmin() || userInfo.getBlackListEndTime() > System.currentTimeMillis()) {
            return;
        }
        // 赚速比较
        BigInteger value = powerChild.getChildEarnSpeed();
        long serverId = GameServer.getInstance().getServerId();
        String param = JSON.toJSONString(powerChild);

        rankListModel.rankChange(userId, UserMgr.parseUserBaseInfo(userInfo, serverId), value, param);
        // 进入前十名分享到世界
        int rank = rankListModel.unlockGetMyRank(userId);
        if (rank <= GameConfig.CHILD_RANK_SHARE_NUM && rank != -1) {
            WorldMessageMgr.worldNotify(GamePlayerMgr.getOnlinePlayer(userId), eMessageType.ChildRank.getValue(), param);
        }
    }

    /**
     * 用户信息变化
     */
    public static void changeUserInfo(long userId) {
        UserInfo userInfo = UserMgr.getUserInfo(userId);
        if(null == userInfo){
            return;
        }
        //管理员账号不参与排行
        if (userInfo.isAdmin() || userInfo.getBlackListEndTime() > System.currentTimeMillis()) {
            return;
        }

        for (Map<Integer, RankListModel> m : rankListModelMap.values()) {
            for (RankListModel model : m.values()) {
                synchronized (model) {
                    UserRank userRank = model.getPlayerUserRank(userId);
                    if (userRank != null) {
                        RankMgr.changeUserRank(model.getBigRankType(), userId, userRank.getValue(), model.getRankType(), userRank.getParam());
                    }
                }
            }
        }
    }


    public static void reloadActivityRank() {
        for (ActivityInfo activityInfo : NormalActivityMgr.getRankActivityInfoList()) {// 加载冲榜活动
            // 不存在的活动才重新加载
            if (null == getRankListModelByType(eBigRankType.Normal.getValue(), activityInfo.getActivityId())) {
                if (activityInfo.getType() == eActivityType.CrossRankActivity.getValue()) {
                    loadCrossActivityRank(activityInfo);
                } else {
                    loadLocalActivityRank(activityInfo);
                }
            }
        }
    }

    private static void loadLocalActivityRank(ActivityInfo activityInfo) {
        RankListModel rankListModel = new RankListModel(eBigRankType.Normal.getValue(), activityInfo.getActivityId());
        int rankNum = ActivityHelper.getMaxRank(NormalActivityMgr.getActivityConditionInfoList(activityInfo.getActivityId()));
        if (rankNum <= 0) {
            rankNum = GameConfig.RANK_DEFAULT_MAX_COUNT;
        }
        rankListModel.setRankNum(rankNum);
        rankListModel.setRankList(getActivityRankList(activityInfo.getActivityId(), rankNum));
        rankListModelMap.get(eBigRankType.Normal.getValue()).put(activityInfo.getActivityId(), rankListModel);
    }

    private static void loadCrossActivityRank(ActivityInfo activityInfo) {
        RankListModel rankListModel = new RankListModel(eBigRankType.Normal.getValue(), activityInfo.getActivityId());
        int conditionType = ActivityHelper.getCrossRankConditionType(activityInfo.getType(), activityInfo.getChildType());
        int rankNum = NormalActivityMgr.getActivityRankNumByActivityParam(activityInfo);
        int rankNum2 = ActivityHelper.getMaxRankByConditionType(conditionType, NormalActivityMgr.getActivityConditionInfoList(activityInfo.getActivityId()));
        if (rankNum2 > rankNum) {
            rankNum = rankNum2;
        }
        if (rankNum <= 0) {
            rankNum = GameConfig.RANK_DEFAULT_MAX_COUNT;
        }
        rankListModel.setRankNum(rankNum);
        rankListModel.setRankList(getCrossActivityRankList(activityInfo.getActivityId(), conditionType, rankNum));
        rankListModelMap.get(eBigRankType.Normal.getValue()).put(activityInfo.getActivityId(), rankListModel);
    }

    public static void changeUnionRank(UnionInfo unionInfo) {
        if (null != unionInfo) {
            UnionRank unionRank = unionRankListModel.rankChange(unionInfo.getUnionUid(), UnionHelper.parseUnionBaseInfo(unionInfo, UserMgr.getUserInfo(unionInfo.getMasterUserId()), GameServer.getInstance().getServerId()));
            if (null != unionRank) {
                CrossDataMgr.groupUnionRankChange(unionRank);
            }
        }
    }

    /**
     * 跨服商会
     */
    public static void changeUnionRank(CrossUnionInfo unionInfo) {
        if(null != unionInfo) {
            UnionRank unionRank = unionRankListModel.rankChange(unionInfo.getUnionUid(), CrossUnionMgr.parseUnionBaseInfo(unionInfo));
            if(null != unionRank){
                CrossDataMgr.groupUnionRankChange(unionRank);
            }
        }
    }


    public static void removeUnionRank(String unionUid) {
        unionRankListModel.removeRank(unionUid);
    }

    private static LinkedList<UserRank> getActivityRankList(int activityId, int rankNum) {
        List<UserActivityConditionData> userActivityConditionDataList = UserActivityBussiness.getUserActivityConditionDataList(activityId, rankNum);
        return parseUserRankList(userActivityConditionDataList, rankNum);
    }

    public static LinkedList<UserRank> getCrossActivityRankList(int activityId, int conditionType, int rankNum) {
        List<UserActivityConditionData> userActivityConditionDataList = UserActivityBussiness.getUserActivityConditionDataList(activityId, conditionType, rankNum);
        return parseUserRankList(userActivityConditionDataList, rankNum);
    }

    public static LinkedList<UserRank> parseUserRankList(List<UserActivityConditionData> userActivityConditionDataList, int rankNum) {
        LinkedList<UserRank> userRankList = new LinkedList<>();
        if (null != userActivityConditionDataList) {
            for (UserActivityConditionData userActivityConditionData : userActivityConditionDataList) {
                if (!ActivityHelper.isConditionRankNeedZero(userActivityConditionData.getType())) {//防止重启导致的0分上榜
                    if (userActivityConditionData.getValue().equals(BigInteger.ZERO)) {
                        continue;
                    }
                }
                UserRank userRank = new UserRank();
                userRank.setBigRankType(eBigRankType.Normal.getValue());
                userRank.setType(userActivityConditionData.getActivityId());
                userRank.setUserId(userActivityConditionData.getUserId());
                userRank.setValue(userActivityConditionData.getValue());
                userRank.setLastUpdateTime(userActivityConditionData.getModifyTime());
                UserInfo userInfo = UserMgr.getUserInfo(userActivityConditionData.getUserId());
                if (null == userInfo) {
                    continue;
                }
                userRank.setUserBaseInfo(UserMgr.parseUserBaseInfo(userInfo, GameServer.getInstance().getServerId()));
                userRank.setParam(userActivityConditionData.getParam());
                userRankList.add(userRank);
                if (userRankList.size() >= rankNum) {
                    break;
                }
            }
        }
        userRankList.sort((o1, o2) -> {
            int result = o2.getValue().compareTo(o1.getValue());
            if (0 == result) {
                result = (int) (o1.getLastUpdateTime() - o2.getLastUpdateTime());
            }
            return result;
        });
        return userRankList;
    }

    private static LinkedList<UnionRank> getUnionRankListFromDb(int rankNum) {
        List<UnionInfo> unionInfoList = UnionBussiness.getUnionInfoList(rankNum);
        return parseUnionRankList(unionInfoList);
    }

    private static LinkedList<UnionRank> parseUnionRankList(List<UnionInfo> unionInfoList) {
        LinkedList<UnionRank> unionRankList = new LinkedList<>();
        if (null != unionInfoList) {
            for (UnionInfo unionInfo : unionInfoList) {
                UnionRank unionRank = UnionRankListModel.initRank(unionInfo.getUnionUid(), UnionHelper.parseUnionBaseInfo(unionInfo, UserMgr.getUserInfo(unionInfo.getMasterUserId()), GameServer.getInstance().getServerId()));
                unionRankList.add(unionRank);
            }
        }
        unionRankList.sort((o1, o2) -> o2.getUnionBaseInfo().getTotalEarnSpeed().compareTo(o1.getUnionBaseInfo().getTotalEarnSpeed()));
        return unionRankList;
    }

    private static LinkedList<UnionRank> parseCrossUnionRankList(List<CrossUnionInfo> unionInfoList) {
        LinkedList<UnionRank> unionRankList = new LinkedList<>();
        if(null != unionInfoList){
            for(CrossUnionInfo unionInfo : unionInfoList){
                UnionRank unionRank = UnionRankListModel.initRank(unionInfo.getUnionUid(), CrossUnionMgr.parseUnionBaseInfo(unionInfo));
                unionRankList.add(unionRank);
            }
        }
        unionRankList.sort((o1, o2) -> o2.getUnionBaseInfo().getTotalEarnSpeed().compareTo(o1.getUnionBaseInfo().getTotalEarnSpeed()));
        return unionRankList;
    }

    public static int parseCrossRankType(int crossRankType) {
        if (eRankType.CrossEarnSpeed.getValue() == crossRankType) {
            return eRankType.EarnSpeed.getValue();
        } else if (eRankType.CrossPatronsAbility.getValue() == crossRankType) {
            return eRankType.PatronsAbility.getValue();
        } else if (eRankType.CrossBeautyIntimacy.getValue() == crossRankType) {
            return eRankType.BeautyIntimacy.getValue();
        } else if (eRankType.CrossManorProsperousValue.getValue() == crossRankType) {
            return eRankType.ManorProsperousValue.getValue();
        } else if (eRankType.CrossWineShopPopularityValue.getValue() == crossRankType) {
            return eRankType.WineShopPopularityValue.getValue();
        } else if (eRankType.CrossFishPondScore.getValue() == crossRankType) {
            return eRankType.FishPondScore.getValue();
        } else if (eRankType.CrossGrandChildEarnSpeed.getValue() == crossRankType) {
            return eRankType.GrandChildEarnSpeed.getValue();
        } else if (eRankType.CrossAssistantDressOnValue.getValue() == crossRankType) {
            return eRankType.AssistantDressOnValue.getValue();
        } else if (eRankType.CrossWingRoomComfortValue.getValue() == crossRankType) {
            return eRankType.WingRoomComfortValue.getValue();
        } else if(eRankType.CrossDrugStroeTongBiValue.getValue() == crossRankType){
            return eRankType.DrugStroeTongBiValue.getValue();
        } else if (eRankType.CrossWineryAroma.getValue() == crossRankType) {
            return eRankType.WineryAroma.getValue();
        } else if (eRankType.CrossCricketScore.getValue() == crossRankType) {
            return eRankType.CricketScore.getValue();
        } else if (eRankType.CorssHistoryMaxAbility.getValue() == crossRankType) {
            return eRankType.HistoryMaxAbility.getValue();
        }else if (eRankType.CrossKowloonProsperousValue.getValue() == crossRankType) {
            return eRankType.KowloonProsperousValue.getValue();
        } else if (eRankType.CrossWingRoomWindWaterValue.getValue() == crossRankType) {
            return eRankType.WingRoomWindWaterValue.getValue();
        } else if (eRankType.CrossMusicRoomRank.getValue() == crossRankType) {
            return eRankType.MusicRoomRank.getValue();
        } else if (eRankType.CurioCrossScoreValue.getValue() == crossRankType) {
            return eRankType.CurioScoreValue.getValue();
        } else {
            return crossRankType;
        }
    }


    /**
     * 本服膜拜
     *
     * @param player
     * @param rankType
     * @return
     */
    public static RankProto.RankWorshipRespMsg.Builder rankWorship(GamePlayer player, int rankType) {
        RankProto.RankWorshipRespMsg.Builder respMsg = RankProto.RankWorshipRespMsg.newBuilder();
        if (eRankType.UnionEarnSpeed.getValue() == rankType) {
            UnionRankListModel unionRankListModel = RankMgr.getUnionRankList();
            if (null == unionRankListModel || unionRankListModel.getRankList().size() <= 0) {
                respMsg.setRet(GameErrorCode.E_RANK_WORSHIP_NO_DATA);
                return respMsg;
            }
            RankProto.UnionRankTempMsg.Builder unionRankMsg = RankPb.parseUnionRankTempMsg(unionRankListModel.getWorshipRankData());
            if (unionRankMsg != null) {
                respMsg.setUnionRankData(unionRankMsg);
                respMsg.setRankNum(unionRankListModel.unlockGetMyRank(unionRankMsg.getUnionUid()));
            }
        } else if (eRankType.EarnSpeed.getValue() == rankType || eRankType.PatronsAbility.getValue() == rankType ||
                eRankType.BeautyIntimacy.getValue() == rankType) {
            RankListModel rankListModel = RankMgr.getRankListModelByType(eBigRankType.Normal.getValue(), rankType);
            if (null == rankListModel || rankListModel.getRankList().size() <= 0) {
                respMsg.setRet(GameErrorCode.E_RANK_WORSHIP_NO_DATA);
                return respMsg;
            }
            RankProto.RankTempMsg.Builder userRankMsg = RankPb.parseRankTempMsg(rankListModel.getWorshipRankData());
            if (userRankMsg != null) {
                respMsg.setRankData(userRankMsg);
                respMsg.setRankNum(rankListModel.unlockGetMyRank(userRankMsg.getUserId()));
            }
        }
        RankWorshipResult rankWorshipResult = RankMgr.worship(player, rankType);
        respMsg.setRet(rankWorshipResult.getRet());
        respMsg.setReward(PropertyHelper.parsePropertyToString(rankWorshipResult.getReward()));
        respMsg.setEffectMammonSkill(rankWorshipResult.getEffectMammonSkill());
        return respMsg;
    }


    /**
     * 膜拜排行榜
     */
    public static RankWorshipResult worship(GamePlayer player, int rankType) {
        AttributeModule attributeModule = player.getModule(AttributeModule.class);
        long value = attributeModule.getAttribute(ePlayerAttrType.RankWorship);
        RankWorshipResult rankWorshipResult = new RankWorshipResult();
        if ((value & ((int) Math.pow(2, rankType))) != 0) {
            rankWorshipResult.setRet(GameErrorCode.E_RANK_WORSHIP_ALREADY);
            return rankWorshipResult;
        }
        attributeModule.setAttribute(ePlayerAttrType.RankWorship, value | ((int) Math.pow(2, rankType)));
        long ingots = ConfigMgr.getWorshipRewardIngots();
        int effectMammonSkill = 0;
        MammonEffectResult mammonResult = player.getModule(MammonModule.class).isMammonSkillEffect(eSkillType.MammonRankWorshipAddIngots.getValue(), ingots);
        if (mammonResult.getEffectMammonSkill() > 0) {
            ingots = mammonResult.getValue();
            effectMammonSkill = mammonResult.getEffectMammonSkill();
        }
        Property reward = new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(ingots));
        reward.addProperty(GameConfig.GAME_MONEY_INGOTS, CurioMgr.getSkillAdditionBySkillType(eSkillType.CurioRankLikeIngotsAddSkill.getValue(), player, 0));
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Rank, eLogMoneyType.RankWorship);
        attributeModule.addAttribute(ePlayerAttrType.WorshipTotalTimes, 1);
        //成就、任务
        player.notifyListener(eGamePlayerEventType.WorshipTimes.getValue(), 1);
        player.notifyListener(eGamePlayerEventType.WorshipTotalTimes.getValue(), attributeModule.getAttribute(ePlayerAttrType.WorshipTotalTimes));
        LogMgr.addLogWorship(player.getUserId(), rankType, effectMammonSkill, PropertyHelper.parsePropertyToString(reward));

        rankWorshipResult.setEffectMammonSkill(effectMammonSkill);
        rankWorshipResult.setReward(reward);

        player.getModule(CurioModule.class).addUserCurioCountData(eCurioConditionType.GiveLikeRankTimes.getType(), 1);
        return rankWorshipResult;
    }

    /**
     * 跨服膜拜回调
     */
    public static RankProto.RankWorshipRespMsg.Builder crossWorshipCallback(GamePlayer player, RankProto.CrossGroupWorshipRespMsg respMsg) {
        RankProto.RankWorshipRespMsg.Builder builder = RankProto.RankWorshipRespMsg.newBuilder();
        if (respMsg.getRet() != 0) {
            builder.setRet(respMsg.getRet());
            return builder;
        }
        RankWorshipResult rankWorshipResult = RankMgr.worship(player, respMsg.getType());
        if (rankWorshipResult.getRet() != 0) {
            builder.setRet(rankWorshipResult.getRet());
            return builder;
        }
        if (respMsg.hasRankData()) {
            builder.setRankData(respMsg.getRankData());
        }
        if (respMsg.hasUnionRankData()) {
            builder.setUnionRankData(respMsg.getUnionRankData());
        }
        if (respMsg.hasRankNum()) {
            builder.setRankNum(respMsg.getRankNum());
        }
        if (rankWorshipResult.getReward() != null) {
            builder.setReward(PropertyHelper.parsePropertyToString(rankWorshipResult.getReward()));
        }
        builder.setEffectMammonSkill(rankWorshipResult.getEffectMammonSkill());
        builder.setRet(rankWorshipResult.getRet());
        return builder;
    }


}
